package datasv.courseProduce_datasv;

import logic.courseProduce_logic.CourseBasic;
import po.CourseAssistPO;
import po.CourseBasicPO;
import data.datafactory.DatabaseOperator;

public class GetCourseBasic {
	public static void main(String[] args) {
		System.out.println(new GetCourseBasic().getCourseBasic("00106130020")
				.getCourseName());
	}

	public CourseBasicPO getCourseBasic(String courseID) {
		return getInSql(courseID);
	}

	private CourseBasicPO getInSql(String courseID) {
		String collegeID = courseID.substring(0, 3);
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist() || !op.ifIDExist("course_list", courseID)) {
			return null;
		}
		int columnNum = AddCourseBasic.columnNum;
		String[] columnName = AddCourseBasic.columnName;
		String[] result = new String[columnNum];
		for (int i = 0; i < columnName.length; i++) {
			String m = op.getOneInform(courseID, "course_list", columnName[i]);
			try {
				m.equals(null);
				//System.out.println(columnName[i] + " is " + m);
			} catch (NullPointerException e) {
				//System.out.println(columnName[i] + " is " + m);
			}
			//System.out.println(columnName[i] + " : " + m);
			result[i] = m;
		}
		if(!ifAllNull(result)){
			return null;
		}
		return new CourseBasicPO(courseID, result[6],
				Integer.parseInt(result[3]), Integer.parseInt(result[3]),
				Integer.parseInt(result[3]), Integer.parseInt(result[4]),
				result[1], collegeID, result[2], Integer.parseInt(result[5]));
	}
	private boolean ifAllNull(String[] m){
		for (int i = 0; i < m.length; i++) {
			try{
				m.equals(null);
			}catch(NullPointerException e){
				return false;
			}
		}
		return true;
	}
}
